package com.cat.DataStructure04;

import java.util.HashMap;
import java.util.HashSet;
import java.util.Map;

/**
 * @author 曲大人的喵
 * @description https://leetcode.cn/contest/weekly-contest-478/problems/minimum-absolute-distance-between-mirror-pairs/
 * @create 2025/11/30 10:36
 * @since JDK17
 */

public class Solution27 {
    int reverse(int x) {
        int y = 0;
        while (x > 0) {
            y = y * 10 + x % 10;
            x /= 10;
        }
        return y;
    }
    public int minMirrorPairDistance(int[] nums) {
        int n = nums.length, ans = n;
        Map<Integer, Integer> map = new HashMap<>();
        for (int i = 0; i < n; i++) {
            if (map.containsKey(nums[i])) {
                ans = Math.min(ans, i - map.get(nums[i]));
            }
            map.put(reverse(nums[i]), i);
        }
        return ans == n ? -1 : ans;
    }
}
